package com.lashou.chunshen.lashoutuangou.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.lashou.chunshen.lashoutuangou.R;
import com.lashou.chunshen.lashoutuangou.bean.HotFilm;
import com.lashou.chunshen.lashoutuangou.tools.PicassoUtils;

import java.util.List;

/**
 * 热门电影recycleView适配器
 * Created by momo on 2016/9/8.
 */

public class GalleryAdapter extends
        RecyclerView.Adapter<GalleryAdapter.ViewHolder> {

    private LayoutInflater mInflater;
    private HotFilm mDatas;
    private Context context;

    public GalleryAdapter(Context context, HotFilm datats) {
        this.mInflater = LayoutInflater.from(context);
        this.mDatas = datats;
        this.context = context;
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {
        public ViewHolder(View arg0) {
            super(arg0);
        }

        ImageView mImg;
        TextView mTxt;
        TextView sTxt;
    }

    @Override
    public int getItemCount() {
        return mDatas.getResults().size();
    }

    /**
     * 创建ViewHolder
     */
    @Override
    public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
        View view = mInflater.inflate(R.layout.activity_index_gallery_item,
                viewGroup, false);
        ViewHolder viewHolder = new ViewHolder(view);
        viewHolder.mImg = (ImageView) view.findViewById(R.id.id_index_gallery_item_image);
        viewHolder.mTxt = (TextView) view.findViewById(R.id.id_index_gallery_item_text);
        viewHolder.sTxt = (TextView) view.findViewById(R.id.id_index_gallery_score_text);
        return viewHolder;
    }

    /**
     * 设置值
     */
    @Override
    public void onBindViewHolder(final ViewHolder viewHolder, final int i) {
        PicassoUtils.loadImageViewHolder(context, mDatas.getResults().get(i).getImageUrl(), R.drawable.home_class_default_icon, viewHolder.mImg);
        viewHolder.mTxt.setText(mDatas.getResults().get(i).getFilmName());
        viewHolder.sTxt.setText(mDatas.getResults().get(i).getGrade());
    }

}
